package com.kk.controller;

import com.kk.Entry.R;
import com.kk.utils.MyAliYunOssUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

@RestController
@RequestMapping("upload")
public class ImgController {
    @Autowired
    private MyAliYunOssUtils aliYunOssUtils;

    @PostMapping
    public R imageUpload(MultipartFile image) throws IOException {
        byte[] imageBytes = image.getBytes();
        String filename = image.getOriginalFilename();
        String[] split = filename.split("\\.");
        String s = UUID.randomUUID().toString() + "." + split[split.length - 1];
        String upload = aliYunOssUtils.upload(s, imageBytes);
        return R.success(upload);


    }

}
